package com.ug.managent.service.impl;

import java.util.List;
import com.ug.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ug.managent.mapper.WorkOrderMapper;
import com.ug.managent.domain.WorkOrder;
import com.ug.managent.service.IWorkOrderService;

/**
 * 工单主Service业务层处理
 * 
 * @author Leo
 * @date 2025-04-22
 */
@Service
public class WorkOrderServiceImpl implements IWorkOrderService 
{
    @Autowired
    private WorkOrderMapper workOrderMapper;

    /**
     * 查询工单主
     * 
     * @param id 工单主主键
     * @return 工单主
     */
    @Override
    public WorkOrder selectWorkOrderById(Long id)
    {
        return workOrderMapper.selectWorkOrderById(id);
    }

    /**
     * 查询工单主列表
     * 
     * @param workOrder 工单主
     * @return 工单主
     */
    @Override
    public List<WorkOrder> selectWorkOrderList(WorkOrder workOrder)
    {
        return workOrderMapper.selectWorkOrderList(workOrder);
    }

    /**
     * 新增工单主
     * 
     * @param workOrder 工单主
     * @return 结果
     */
    @Override
    public int insertWorkOrder(WorkOrder workOrder)
    {
        workOrder.setCreateTime(DateUtils.getNowDate());
        return workOrderMapper.insertWorkOrder(workOrder);
    }

    /**
     * 修改工单主
     * 
     * @param workOrder 工单主
     * @return 结果
     */
    @Override
    public int updateWorkOrder(WorkOrder workOrder)
    {
        workOrder.setUpdateTime(DateUtils.getNowDate());
        if(workOrder.getOrderStatus()==0){
            workOrder.setOrderStatus(1L);
            return workOrderMapper.updateWorkOrder(workOrder);
        }else if(workOrder.getOrderStatus()==1) {
            return workOrderMapper.clearWorkOrder(workOrder.getId());
        }

        return workOrderMapper.updateWorkOrder(workOrder);
    }

    /**
     * 批量删除工单主
     * 
     * @param ids 需要删除的工单主主键
     * @return 结果
     */
    @Override
    public int deleteWorkOrderByIds(Long[] ids)
    {
        return workOrderMapper.deleteWorkOrderByIds(ids);
    }

    /**
     * 删除工单主信息
     * 
     * @param id 工单主主键
     * @return 结果
     */
    @Override
    public int deleteWorkOrderById(Long id)
    {
        return workOrderMapper.deleteWorkOrderById(id);
    }

    @Override
    public List<WorkOrder> selectWorkerOrderList(long id,long status) {
        WorkOrder workOrder = new WorkOrder();
        workOrder.setAssigneeId(id);
        workOrder.setOrderStatus(status);
        return workOrderMapper.selectWorkerOrderList(workOrder);
    }
}
